#!/usr/bin/env python
# -*-coding:utf-8-*-


import json

class BaseCnofig(object):
    def update(self, name, value):
        if name in self.__dict__:
            self.__dict__[name] = value
        else:
            raise Exception("%s not the attribute" % (name,))

    def save(self, path):
        f = open(path, 'w')
        f.write(json.dumps(self.__dict__, ensure_ascii=False, indent=4))

    def load(self, path):
        f = open(path, 'r')
        data = json.load(f)
        for k, v in data.items():
            self.update(k, v)


class BiLSTMConfig(BaseCnofig):
    def __init__(self):
        super(BiLSTMConfig, self).__init__()
        self.lr = 0.01
        self.char_dim = 100
        self.lstm_dim = 100
        self.num_tags = -1
        self.num_chars = 0
        self.optimizer = "adam"
        self.clip = 5
        self.dropout_keep = 0.5


class NBiLSTMConfig(BaseCnofig):
    def __init__(self):
        super(NBiLSTMConfig, self).__init__()
        self.lr = 0.01
        self.char_dim = 100
        self.lstm_dim = 100
        self.num_tags = -1
        self.num_chars = 0
        self.optimizer = "adam"
        self.clip = 5
        self.dropout_keep = 0.5
        self.seg_dim = 20
        self.num_seg = 4
        self.pos_dim = 50
        self.num_pos = -1
        self.num_char_type = -1
        self.char_type_dim = 20


class TrainConfig(BaseCnofig):
    def __init__(self):
        super(TrainConfig, self).__init__()
        self.train_path = ""
        self.dev_path = ""
        self.test_path = ""
        self.pre_embed_path = ""
        self.out_dir = ""
        self.embedding_size = 100
        self.max_epoch = 100
        self.steps_check = 100
        self.batch_size = 32
        self.model = "bilstm"
        self.dropout = 0.5
        self.map_file_path = ""


if __name__ == '__main__':
    train_config = TrainConfig()
    # train_config.save("./config/ner_train.json")
    lst_config = NBiLSTMConfig()
    lst_config.save("./config/ner_lstm.json")
    print(train_config.embedding_size)
